package com.mystudy.leetcode.problem.other.p_804;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @author 周志龙
 * @Email 15216876513@163.com
 * @Date on 2019/7/10 23:23
 * @Description 唯一摩斯密码词
 */
public class Solution {
    private static final Logger LOGGER = LoggerFactory.getLogger(Solution.class);

    @Test
    public void test() {
        int i = uniqueMorseRepresentations(new String[]{"gin", "zen", "gig", "msg"});
        LOGGER.debug("i = [ {} ]", i);
    }


    public int uniqueMorseRepresentations(String[] words) {
        String[] values = new String[]{".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
        Map<Character, String> map = new HashMap<>();
        char first = 'a';
        for (String value : values) {
            map.put(first, value);
            first = (char) (first + 1);
        }
        LOGGER.debug("map = [ {} ]", map);
        Set<String> result = new HashSet<>();
        for (String word : words) {
            char[] chars = word.toCharArray();
            StringBuilder r = new StringBuilder();
            for (char c : chars) {
                String s = map.get(c);
                r.append(s);
            }
            result.add(r.toString());
        }
        return result.size();
    }
}
